package com.basic.config;

import com.basic.interceptor.TokenInterceptor;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Component
public class IntercepterConfig implements WebMvcConfigurer {

    private TokenInterceptor tokenInterceptor;

    //构造方法
    public IntercepterConfig(TokenInterceptor tokenInterceptor){
        this.tokenInterceptor = tokenInterceptor;
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry){
        List<String> excludePath = new ArrayList<>();
        excludePath.add("/login/jwt/login/login"); //登录
        excludePath.add("/basic/user/addUser"); // 添加用户
        excludePath.add("/basic/user//updateUser"); // 修改用户
        excludePath.add("/basic/user/getRefreshUser"); // 用户刷新
//        excludePath.add("/basic/user/queryBasicUserAll"); // 用户列表
        excludePath.add("/util/upload/importPicture"); // 图片上传
        excludePath.add("/util/upload/toUpload"); // 图片上传
        excludePath.add("/temp-image/**"); // 图片显示
        excludePath.add("/basic/productinfo/queryProductInfoById/**");//商品详情
        excludePath.add("/basic/productinfo/queryRelevant/**");//关联商品查询
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(excludePath);
        WebMvcConfigurer.super.addInterceptors(registry);//除了登陆接口其他所有接口都需要token验证

    }

}

